// UPSMonitorDoc.h : interface of the CUPSMonitorDoc class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_UPSMONITORDOC_H__6D390A7B_EF14_4000_86A6_D5C8560C395F__INCLUDED_)
#define AFX_UPSMONITORDOC_H__6D390A7B_EF14_4000_86A6_D5C8560C395F__INCLUDED_

#include "DlgAlert.h"	// Added by ClassView
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include   <Mmsystem.h>  
#pragma   comment(lib,   "Winmm.lib")   


#include "ado.h"
#include "Ini.h"
//class CClientSocket;
class CNetworkManager;
class CNodeStatus;

UINT SearchNetForNodeThread(LPVOID lparam);

class CUPSMonitorDoc : public CDocument
{
protected: // create from serialization only
	CUPSMonitorDoc();
	DECLARE_DYNCREATE(CUPSMonitorDoc)

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CUPSMonitorDoc)
	public:
	virtual BOOL OnNewDocument();
	virtual void Serialize(CArchive& ar);
	virtual void OnCloseDocument();
	//}}AFX_VIRTUAL

// Implementation
public:
	BOOL isDEBUG();
	BOOL m_DEBUG;
	BOOL SetHackBit(BOOL bset);
	int ManualStatusReturn();
	int StatusSearch();
	double GetRand(double MIN, double MAX);
	int StatusReturn();
	void OnAlertMessage();
	CDlgAlert m_dlgalert;
	BOOL ShowAlertFromDB(BOOL breflash=TRUE);
	ShowAlertFromDB(CString strField, CString strFilter,COleDateTime dtAlertTimeBegin,COleDateTime dtAlertTimeEnd);
	BOOL SaveAlertToDB(CNodeStatus *pNodeStatus, COleDateTime dtAlertTime, int nAlertType);
	CWinThread* pSearchNetForNodeThread;
	BOOL QueryNodeStatus(CNodeStatus *pNodeStatus, BOOL bWaitReturn);
	BOOL SetNodeStatus(CNodeStatus *pNodeStatus,BOOL bWaitReturn);
	//static UINT SearchNetForNodeThread(LPVOID lparam);
	DWORD WINAPI SearchNodeThread (PVOID pParam);
	int HexAtBitN(int nFlag, int nBit);
	BOOL DeleteNodeFromDB(CString strNodeAddCde);
	BOOL DeleteNode(CString strNodeAddCde);
	BOOL SaveNode(CNodeStatus *pNodeStatus, BOOL bNewNode);
	int NodeSelected(int nAddCde);
	CIni m_ini;
	BOOL SaveNodeToDB(CNodeStatus* pNodeStatus,BOOL bNewNode);
	void checkTimeout();
	CView * GetView(CRuntimeClass* pClass);
	int flagAtBitN(unsigned char ch,int nBit);
	int parsePackage(const void *lpBuf, int nBufLen);
	void HEXToDSP(char *strHex,char *strDsp,int nCount);
	void DSPToHEX(char *strDsp, char *strHex,int nCount);
	int  GetNodeInfoFromDB(BOOL bInitLoad);
	void SearchNetForNode();
	int updateNodeStatus();
	//int ProcessPendingRead(CClientSocket *);
	//CClientSocket * m_pSocket;
	CNetworkManager* m_pNetMgr;
	CAdoConnection m_adoConnection;
	CAdoRecordSet  m_adoNodeRecordSet;
	CAdoRecordSet  m_adoAlertRecordSet;
	CAdoRecordSet  m_adoAlertRecordSetQuery;
	CMapStringToOb m_mpNodes;
	CMapStringToOb m_mpAlertNodes;
	CList <CString ,CString&>  m_lsNodeReqs;
	CList <CString ,CString&>  m_lsNodeRsps;
	CList <CString ,CString&>  m_lsNodeManualRsps;
	//CMapStringToOb m_mpAlertNodes;

	virtual ~CUPSMonitorDoc();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:	
	BOOL m_bHackBit;
	//{{AFX_MSG(CUPSMonitorDoc)
	afx_msg void OnMenuitemCon();
	afx_msg void OnMenuitemSend();
	afx_msg void OnMenuitemScan();	
	//}}AFX_MSG
	//afx_msg void OnAlertMessage(WPARAM wParam, LPARAM lParam);
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_UPSMONITORDOC_H__6D390A7B_EF14_4000_86A6_D5C8560C395F__INCLUDED_)
